package com.iyimo.control{
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.System;
	import flash.text.TextField;
	import flash.utils.Timer;
	import flash.utils.getTimer;
	
	public class YFPS extends Sprite{
		private var _tick:int;
		private var _time:int;
		
		private var _fpsTxt:TextField;
		private var _memTxt:TextField;
		
		public function YFPS(){
			super();
			
			_fpsTxt = new TextField();
			_fpsTxt.textColor = 0x00FF00;
			addChild(_fpsTxt);
			
			_memTxt = new TextField();
			_memTxt.y = 20;
			_memTxt.textColor = 0x00FF00;
			addChild(_memTxt);
		}
		
		public static function initialize(iparent:DisplayObjectContainer):void{
			var fps:YFPS = new YFPS();
			iparent.addChild(fps);
			fps.run();
		}
		
		public function run():void{
			_tick = 0;
			_time = getTimer();
			
			addEventListener(Event.ENTER_FRAME, onFrame);
		}
		
		private function onFrame(e:Event):void{
			_tick++;
			var t:int = getTimer();
			if ((t - _time) > 1000){
				_time = t;
				
				_fpsTxt.text = "FPS: " + _tick;
				_memTxt.text = "Mem: " + int(System.totalMemory * 0.000001) + "m";
				_tick = 0;
			}
			
		}
	}
}